package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.service.ShopCarService;

public class ShopCarServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		ShopCarService scs = ctx.getBean(ShopCarService.class);
		if(req.getSession().getAttribute("user")==null||"".equals(req.getSession().getAttribute("user"))){
			resp.sendRedirect("login.jsp");
			return;
		}else{
			req.setAttribute("shopcarlist", scs.getall(req.getSession().getAttribute("user").toString()));
			req.getRequestDispatcher("shopcar.jsp").forward(req, resp);
		}
	}
	
	
}
